/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-01-26
 * Time: 20:58
 */
public class ListNode {
    public int val;
    public ListNode next;
    public ListNode(int val) {
        this.val = val;
    }
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        // 创建一个新的链表
        ListNode list3 = new ListNode(0);
        ListNode cur3 = list3;
        // 当cur1==null或者cur2==null跳出循环
        while (list1 != null && list2 != null) {
            // 1.list1.val>=list2.val
            if (list1.val >= list2.val) {
                cur3.next = list2;
                list2 =list2.next;
            }
            // 2.list1.val<list2.val
            else {
                cur3.next = list1;
                list1 = list1.next;
            }
            cur3 = cur3.next;
        }
        cur3.next = list1 == null ? list2 :list1;
        return list3.next;
    }

    public static void main(String[] args) {
    
    }
}
